import 'package:enterprise_v6_app/app/components/common/custom_text_widget.dart';
import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/dialog/exit_tips.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_picker_photo.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_button_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/common/simple_choice_bean.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/task_closure/task_waiting_management/waiting_management_approval/waiting_management_approval_controller.dart';

/// 候检管理审批详情
class WaitingManagementApprovalPage extends StatelessWidget {
  WaitingManagementApprovalPage({super.key});

  final controller = Get.put(WaitingManagementApprovalController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        titleText: '检查',
      ),
      body: DefaultTabController(
          length: 2,
          child: Column(children: [
            Container(
              height: 54.w,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(8.r),
              ),
              child: TabBar(
                tabs: const [
                  Tab(text: '基本信息'),
                  Tab(text: '预约信息'),
                ],
                dividerColor: Colors.transparent,
                labelPadding: EdgeInsets.only(bottom: 20.w),
                labelStyle: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
                unselectedLabelStyle: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
                labelColor: Colors.black,
                unselectedLabelColor: const Color(0xffA0A7B5),
                indicatorPadding: EdgeInsets.only(top: 35.w, bottom: 10.w),
                indicator: const BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage(
                      AppImages.icon_app_work_plan,
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              child: TabBarView(
                children: [
                  _getBasicInfo(),
                  _getAppointmentInfo(),
                ],
              ),
            ),
            AppGaps.vGap50,
          ])),
      bottomSheet: Container(
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        height: 50.w,
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: const Color(0xffBCBCC5).withOpacity(0.3), // 阴影颜色
              offset: const Offset(0, -5), // 阴影的偏移量，向上偏移，即上方阴影
              blurRadius: 10.0, // 阴影的模糊半径
              spreadRadius: 2.0, // 阴影的扩散半径
            ),
          ],
        ),
        child: Row(
          children: [
            Container(
                height: 40.w,
                width: 120.w,
                margin: EdgeInsets.only(right: 10.w),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: const Color(0xffffffff),
                    border: Border.all(color: const Color(0xffFD6B6B), width: 1.w),
                    borderRadius: BorderRadius.all(Radius.circular(20.w))),
                child: Text(
                  '拒绝准入',
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: const Color(0xffFD6B6B),
                  ),
                )).clickOnce(() {
              // 弹窗提示
              Get.dialog<bool>(ExitTips(
                content: '确认拒绝进入？',
                func: (b) {
                  if (b) {
                    controller.passOrReject(false);
                  }
                },
              ));
            }),
            Expanded(
              child: Container(
                  height: 40.w,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(color: const Color(0xff5C6DFF), borderRadius: BorderRadius.all(Radius.circular(20.w))),
                  child: Text(
                    '允许准入',
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: const Color(0xffffffff),
                    ),
                  )).clickOnce(() {
                controller.passOrReject(true);
              }),
            ),
          ],
        ),
      ),
    );
  }

  /// 获取基本信息
  Widget _getBasicInfo() {
    return Column(
      children: [
        Container(
          height: 38.w,
          width: double.infinity,
          color: AppColors.bg_color_grey,
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.only(left: 16.w),
          child: Text(
            '基本信息',
            style: TextStyle(
              fontSize: 12.sp,
              color: AppColors.text_grey,
            ),
          ),
        ),
        Container(
          height: 2.w,
          color: AppColors.blue_button,
        ),
        Expanded(
            child: Container(
          padding: EdgeInsets.symmetric(horizontal: 16.w),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                _getShowView('车辆外观', controller.vehicleAppearanceList, controller.entity.vehicleAppearance),
                _getShowView('驾驶证', controller.driverSLicenseList, controller.entity.driverLicense),
                _getShowView('行驶证', controller.drivingLicenseList, controller.entity.drivingLicense),
                _getShowView('货物状态', controller.cargoStatusList, controller.entity.goods),
                CustomInputPage(
                  title: '货物数量/t',
                  textInputType: TextInputType.number,
                  reg: '[0-9]',
                  isRequired: false,
                  text: controller.entity.quantityOfGoods == 0 ? '' : controller.entity.quantityOfGoods.toString(),
                  onCallBack: (value) {
                    if (value.isNotEmpty) {
                      controller.entity.quantityOfGoods = int.parse(value);
                    } else {
                      controller.entity.quantityOfGoods = 0;
                    }
                  },
                ),
                CustomInputPage(
                  title: '描述',
                  isRequired: false,
                  text: controller.entity.waitingDescription,
                  onCallBack: (value) {
                    controller.entity.waitingDescription = value;
                  },
                ),
              ],
            ),
          ),
        )),
      ],
    );
  }

  /// 获取展示项
  Widget _getShowView(String title, List<SimpleChoiceBean> choiceList, List<String> imageList) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style: TextStyle(
                fontSize: 14.sp,
                color: const Color(0xff262F38),
              ),
            ),
            CustomSelectButtonPage<SimpleChoiceBean>(
              dataList: choiceList,
              onConfirm: (List<SimpleChoiceBean> value) {
                if (value.isNotEmpty) {
                  switch (title) {
                    case '车辆外观':
                      controller.entity.vehicleAppearanceStatus = int.parse(value.first.id!);
                      break;
                    case '驾驶证':
                      controller.entity.driverLicenseStatus = int.parse(value.first.id!);
                      break;
                    case '行驶证':
                      controller.entity.drivingLicenseStatus = int.parse(value.first.id!);
                      break;
                    case '货物状态':
                      controller.entity.goodsStatus = int.parse(value.first.id!);
                      break;
                  }
                }
              },
            ),
          ],
        ),
        // 图片选择
        CustomPickerPhoto(
          isShowTitle: false,
          imagesList: imageList,
          title: '图片',
        ),
        // Container(
        //   width: 140.w,
        //   height: 80.w,
        //   decoration: BoxDecoration(
        //       borderRadius: BorderRadius.circular(4.w),
        //       color: Colors.white,
        //       border: Border.all(
        //         color: const Color(0xFFEFF2F6),
        //         width: 1,
        //       ),
        //       image: DecorationImage(
        //         image: NetworkImage(Interface.fileUrl + '/2023-09-27/1695890573398signature.png'),
        //       )),
        // ).clickShowLarge(url: Interface.fileUrl + '/2023-09-27/1695890573398signature.png'),
        AppGaps.vGap10,
        Divider(height: 1.w, color: AppColors.bg_color_grey),
      ],
    );
  }

  /// 获取预约信息
  Widget _getAppointmentInfo() {
    return Column(
      children: [
        Container(
          height: 38.w,
          width: double.infinity,
          color: AppColors.bg_color_grey,
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.only(left: 16.w),
          child: Text(
            '预约信息',
            style: TextStyle(
              fontSize: 12.sp,
              color: AppColors.text_grey,
            ),
          ),
        ),
        Container(
          height: 2.w,
          color: AppColors.blue_button,
        ),
        Container(
          height: 64.w,
          color: const Color(0xFFF4F7FF),
          child: Row(
            children: [
              AppGaps.hGap30,
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '驾驶员姓名：${controller.entity.name}',
                    style: TextStyle(
                      fontSize: 16.sp,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  AppGaps.vGap4,
                  Text(
                    '联系方式: ${controller.entity.visitorTelephone}',
                    style: TextStyle(
                      fontSize: 13.sp,
                      color: const Color(0xFF3F425B),
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
        AppGaps.vGap10,
        Expanded(
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 30.w),
            child: SingleChildScrollView(
              child: Column(
                children: [
                  CustomTextWidget.getTextRowView(title: '证件号码：', value: controller.entity.idNo),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '车牌号码', value: controller.entity.licensePlate),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '运输介质：', value: controller.entity.transportMedium),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '车辆状态：', value: controller.entity.carStatus == '1' ? '重载' : '空载'),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '押运员姓名：', value: controller.entity.nameOfEscort),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '所属运输企业：', value: controller.entity.affiliatedUnit),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '对接人：', value: controller.entity.contactPerson),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '对接人电话：', value: controller.entity.personToPersonPhoneNumber),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '预计来访时间：', value: controller.entity.startDate),
                  AppGaps.vGap16,
                  CustomTextWidget.getTextRowView(title: '来访事由：', value: controller.entity.reasonForVisit),
                ],
              ),
            ),
          ),
        )
      ],
    );
  }
}
